/**
 * 
 */
package cn.mxz.robots.province;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import cn.mxz.crawler_single.basic.Request;
import cn.mxz.rds.pojo.GaoKaoProvince;
import cn.mxz.rds.pojo.GaoKaoRank;
import cn.mxz.rds.service.GaoKaoProvinceService;
import cn.mxz.rds.service.GaoKaoRankService;
import cn.mxz.robots.basic.local.Exam;
import cn.mxz.robots.basic.local.IRank;
import cn.mxz.robots.pojo.Student;

/**
 * 辽宁省
 * 
 * 去年排名:完成
 * 
 * @author chenmin<chenmin@mouge.wang>
 * @since 2015-06-24
 */
public class Liaoning extends Exam implements IRank
{

	public Liaoning(Student student)
	{
		super(student);
	}

	@Override
	public String login(String captcha)
	{
		return null;
	}

	@Override
	public String loginParseHtml(String parseHtml)
	{
		return null;
	}

	@Override
	public void initRank()
	{

	}

	@Override
	public void lastYearRank()
	{
		// 文 http://www.gxeduw.com/news/2014/107931.html
		// 理http://www.gxeduw.com/news/2014/107903.html
		Request request = new Request("http://www.gxeduw.com/news/2014/107931.html", mSha1);
		Document result = Jsoup.parse(curlGet(request));

		Elements trs = result.select("table").get(0).select("tr");
		for (int i = 2; i < trs.size(); i++)
		{
			Integer scores;
			if(i == 2)
				scores = Integer.parseInt(trs.get(i).select("td").get(0).text().replaceAll(" ", "").replaceAll("及以上", ""));
			else
				scores = Integer.parseInt(trs.get(i).select("td").get(0).text().replaceAll(" ", ""));
			Integer counters = Integer.parseInt(trs.get(i).select("td").get(1).text());
			Integer rankings = Integer.parseInt(trs.get(i).select("td").get(2).text());
			System.out.println(scores + ":" + counters + ":" + rankings);

			 GaoKaoProvinceService provinceService = new
			 GaoKaoProvinceService();
			 GaoKaoProvince province = provinceService.get(18);
			 GaoKaoRankService rankService = new GaoKaoRankService();
			 GaoKaoRank rank = new GaoKaoRank();
			 rank.setScore(scores);
			 rank.setCount(counters);
			 rank.setType(WEN_KE);
			 rank.setRanking(rankings);
			 rank.setGaoKaoProvince(province);
			 rankService.save(rank);
		}
	}

	public static void main(String[] args)
	{
		new Liaoning(new Student()).initRank();
	}
}
